
function validateFields() {
    return validateName() && validateAddress() && validateDurationKoefficient() && validateShipmentRate();
}
function submitForm() {
    if (validateFields()) {
        document.getElementById("warehouse_form").submit();
    } else {
        alert("Please enter correct data");
    }
}
function submitForm_edit() {
    if (validateFields()) {
        document.getElementById("mainForm").action = "EditWarehouse";
        document.getElementById("mainForm").submit();
    } else {
        alert("Please enter correct data");
    }
}

function submitForm_delete() {
    if (validateFields()) {
        document.getElementById("mainForm").action = "DeleteWarehouse";
        document.getElementById("mainForm").submit();
    } else {
        alert("Please enter correct data");
    }
}

function validateName() {
    var valid = true;

    if (document.getElementById("Name").value == "") {
        document.getElementById("name_error").style.display = "inline";
        valid = false;
    } else {
        document.getElementById("name_error").style.display = "none";
    }
    if (document.getElementById("Name").value.length > 100) {
        document.getElementById("name_length_error").style.display = "inline";
        valid = false;
    } else {
        document.getElementById("name_length_error").style.display = "none";
    }
    return valid;
}

function validateAddress() {
    var valid = true;
    if (document.getElementById("Address").value == "") {
        document.getElementById("address_error").style.display = "inline";
        valid = false;
    } else {
        document.getElementById("address_error").style.display = "none";
    }
    if (document.getElementById("Address").value.length > 200) {
        document.getElementById("address_length_error").style.display = "inline";
        valid = false;
    } else {
        document.getElementById("address_length_error").style.display = "none";
    }
    return valid;
}

function validateDurationKoefficient() {
    var valid = true;
    if (document.getElementById("DurationKoefficient").value == "") {
        document.getElementById("durationKoefficient_error").style.display = "inline";
        valid = false;
    } else {
        document.getElementById("durationKoefficient_error").style.display = "none";
    }
    if (isNaN(document.getElementById("DurationKoefficient").value)||(parseInt(document.getElementById("DurationKoefficient").value)<0)) {
        document.getElementById("durationKoefficient_number_error").style.display = "inline";
        valid = false;

    } else {
        document.getElementById("durationKoefficient_number_error").style.display = "none";
    }
    return valid;
}

function validateShipmentRate() {
    var valid = true;
    if (document.getElementById("ShipmentRate").value == "") {
        document.getElementById("shipmentRate_error").style.display = "inline";
        valid = false;
    } else {
        document.getElementById("shipmentRate_error").style.display = "none";
    }
    if (isNaN(document.getElementById("ShipmentRate").value)||(parseInt(document.getElementById("ShipmentRate").value)<0)) {


        document.getElementById("shipmentRate_number_error").style.display = "inline";
        valid = false;
    } else {
        document.getElementById("shipmentRate_number_error").style.display = "none";
    }
    return valid;
}

//function isNumber(str) {
//    var regDot = "/^\d+.?\d*$/";
//    var bool = true;
//    if (regDot.match(str) == null) {
//        bool = false;
//    } else {
//        bool = true;
//    }
//    return bool;
//}



